package com.yaosheng.thread.thread;

import java.lang.ref.WeakReference;

/**
 * Created by yaosheng on 2021/7/2.
 * 弱引用:只要遇到gc，就会被回收
 */
public class TestWeakReference {

    public static void main(String[] args) {

        WeakReference<M> m = new WeakReference<> (new M ());
        System.out.println (m.get ());
        System.gc ();
        System.out.println (m.get ());

        ThreadLocal<M> tl = new ThreadLocal<> ();
        tl.set (new M ());
        tl.remove ();
    }

    static class M{
        String m = "";
    }
}
